///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct  8 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#include "myframe.h"
#include <string>

using namespace std;

///////////////////////////////////////////////////////////////////////////

MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxSize( 669,479 ), wxDefaultSize );
	
	wxBoxSizer* bSizer1;
	bSizer1 = new wxBoxSizer( wxHORIZONTAL );
	
	m_panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* bSizer6;
	bSizer6 = new wxBoxSizer( wxVERTICAL );
	
	m_panel12 = new wxPanel( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* sbSizer9;
	sbSizer9 = new wxStaticBoxSizer( new wxStaticBox( m_panel12, wxID_ANY, wxT("Display") ), wxVERTICAL );
	
	//m_panDisplay = new wxPanel( m_panel12, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	//m_panDisplay = new MyImagePanel(m_panel12, wxDefaultPosition, wxDefaultSize);
	//sbSizer9->Add( m_panDisplay, 1, wxEXPAND | wxALL, 5 );
	
	wxGridSizer* gSizer111;
	gSizer111 = new wxGridSizer( 0, 2, 0, 0 );

	//m_panDisplay1 = new wxPanel( m_panel12, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	m_panDisplay1=new MyImagePanel(m_panel12, wxDefaultPosition, wxDefaultSize);
	gSizer111->Add( m_panDisplay1, 1, wxEXPAND | wxALL, 5 );

	//m_panDisplay2 = new wxPanel( m_panel12, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	m_panDisplay2=new MyImagePanel(m_panel12, wxDefaultPosition, wxDefaultSize);
	gSizer111->Add( m_panDisplay2, 1, wxEXPAND | wxALL, 5 );

	//m_panDisplay3 = new wxPanel( m_panel12, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	m_panDisplay3=new MyImagePanel(m_panel12, wxDefaultPosition, wxDefaultSize);
	gSizer111->Add( m_panDisplay3, 1, wxEXPAND | wxALL, 5 );

	//m_panDisplay4 = new wxPanel( m_panel12, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	m_panDisplay4=new MyImagePanel(m_panel12, wxDefaultPosition, wxDefaultSize);
	gSizer111->Add( m_panDisplay4, 1, wxEXPAND | wxALL, 5 );


	sbSizer9->Add( gSizer111, 1, wxEXPAND, 5 );

	
	m_panel12->SetSizer( sbSizer9 );
	m_panel12->Layout();
	sbSizer9->Fit( m_panel12 );
	bSizer6->Add( m_panel12, 1, wxEXPAND | wxALL, 5 );
	
	
	m_panel1->SetSizer( bSizer6 );
	m_panel1->Layout();
	bSizer6->Fit( m_panel1 );
	bSizer1->Add( m_panel1, 1, wxEXPAND, 5 );
	
	m_panel2 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* bSizer4;
	bSizer4 = new wxBoxSizer( wxVERTICAL );
	
	m_panel7 = new wxPanel( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* sbSizer1;
	sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( m_panel7, wxID_ANY, wxT("Camera 1") ), wxVERTICAL );
	
	wxGridSizer* gSizer1;
	gSizer1 = new wxGridSizer( 0, 2, 0, 0 );
	
	m_staticText1 = new wxStaticText( m_panel7, wxID_ANY, wxT("Status: "), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText1->Wrap( -1 );
	gSizer1->Add( m_staticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_stxtCamStatus1 = new wxStaticText( m_panel7, wxID_ANY, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0 );
	m_stxtCamStatus1->Wrap( -1 );
	gSizer1->Add( m_stxtCamStatus1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_btCamOpen1 = new wxButton( m_panel7, wxID_ANY, wxT("Open Camera"), wxDefaultPosition, wxDefaultSize, 0 );
	gSizer1->Add( m_btCamOpen1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_btCapture1 = new wxButton( m_panel7, wxID_ANY, wxT("Capture"), wxDefaultPosition, wxDefaultSize, 0 );
	gSizer1->Add( m_btCapture1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	
	sbSizer1->Add( gSizer1, 1, wxEXPAND, 5 );
	
	
	m_panel7->SetSizer( sbSizer1 );
	m_panel7->Layout();
	sbSizer1->Fit( m_panel7 );
	bSizer4->Add( m_panel7, 1, wxEXPAND|wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	m_panel8 = new wxPanel( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* sbSizer2;
	sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( m_panel8, wxID_ANY, wxT("Camera 2") ), wxVERTICAL );
	
	wxGridSizer* gSizer11;
	gSizer11 = new wxGridSizer( 0, 2, 0, 0 );
	
	m_staticText11 = new wxStaticText( m_panel8, wxID_ANY, wxT("Status: "), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText11->Wrap( -1 );
	gSizer11->Add( m_staticText11, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_stxtCamStatus2 = new wxStaticText( m_panel8, wxID_ANY, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0 );
	m_stxtCamStatus2->Wrap( -1 );
	gSizer11->Add( m_stxtCamStatus2, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_btCamOpen2 = new wxButton( m_panel8, wxID_ANY, wxT("Open Camera"), wxDefaultPosition, wxDefaultSize, 0 );
	gSizer11->Add( m_btCamOpen2, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_btCapture2 = new wxButton( m_panel8, wxID_ANY, wxT("Capture"), wxDefaultPosition, wxDefaultSize, 0 );
	gSizer11->Add( m_btCapture2, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	
	sbSizer2->Add( gSizer11, 1, wxEXPAND, 5 );
	
	
	m_panel8->SetSizer( sbSizer2 );
	m_panel8->Layout();
	sbSizer2->Fit( m_panel8 );
	bSizer4->Add( m_panel8, 1, wxEXPAND | wxALL, 5 );
	
	m_panel9 = new wxPanel( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* sbSizer3;
	sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( m_panel9, wxID_ANY, wxT("Camera 3") ), wxVERTICAL );
	
	wxGridSizer* gSizer12;
	gSizer12 = new wxGridSizer( 0, 2, 0, 0 );
	
	m_staticText12 = new wxStaticText( m_panel9, wxID_ANY, wxT("Status: "), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText12->Wrap( -1 );
	gSizer12->Add( m_staticText12, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_stxtCamStatus3 = new wxStaticText( m_panel9, wxID_ANY, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0 );
	m_stxtCamStatus3->Wrap( -1 );
	gSizer12->Add( m_stxtCamStatus3, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_btCamOpen3 = new wxButton( m_panel9, wxID_ANY, wxT("Open Camera"), wxDefaultPosition, wxDefaultSize, 0 );
	gSizer12->Add( m_btCamOpen3, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_btCapture3 = new wxButton( m_panel9, wxID_ANY, wxT("Capture"), wxDefaultPosition, wxDefaultSize, 0 );
	gSizer12->Add( m_btCapture3, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	
	sbSizer3->Add( gSizer12, 1, wxEXPAND, 5 );
	
	
	m_panel9->SetSizer( sbSizer3 );
	m_panel9->Layout();
	sbSizer3->Fit( m_panel9 );
	bSizer4->Add( m_panel9, 1, wxEXPAND | wxALL, 5 );
	
	m_panel10 = new wxPanel( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* sbSizer4;
	sbSizer4 = new wxStaticBoxSizer( new wxStaticBox( m_panel10, wxID_ANY, wxT("Camera Pair 1 and 2") ), wxVERTICAL );
	
	wxBoxSizer* bSizer7;
	bSizer7 = new wxBoxSizer( wxVERTICAL );
	
	m_btCaptureP1 = new wxButton( m_panel10, wxID_ANY, wxT("Capture Pair"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer7->Add( m_btCaptureP1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	
	sbSizer4->Add( bSizer7, 1, wxEXPAND, 5 );
	
	
	m_panel10->SetSizer( sbSizer4 );
	m_panel10->Layout();
	sbSizer4->Fit( m_panel10 );
	bSizer4->Add( m_panel10, 1, wxEXPAND | wxALL, 5 );
	
	m_panel11 = new wxPanel( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* sbSizer5;
	sbSizer5 = new wxStaticBoxSizer( new wxStaticBox( m_panel11, wxID_ANY, wxT("Camera Pair 3 and 2") ), wxVERTICAL );
	
	wxBoxSizer* bSizer8;
	bSizer8 = new wxBoxSizer( wxVERTICAL );
	
	m_btCaptureP2 = new wxButton( m_panel11, wxID_ANY, wxT("Capture Pair"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer8->Add( m_btCaptureP2, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	
	sbSizer5->Add( bSizer8, 1, wxEXPAND, 5 );
	
	
	m_panel11->SetSizer( sbSizer5 );
	m_panel11->Layout();
	sbSizer5->Fit( m_panel11 );
	bSizer4->Add( m_panel11, 1, wxEXPAND | wxALL, 5 );
	
	m_panel101 = new wxPanel( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxStaticBoxSizer* sbSizer7;
	sbSizer7 = new wxStaticBoxSizer( new wxStaticBox( m_panel101, wxID_ANY, wxT("Calibration") ), wxVERTICAL );

	m_btShowCorners = new wxButton( m_panel101, wxID_ANY, wxT("Show Corners"), wxDefaultPosition, wxDefaultSize, 0 );
	sbSizer7->Add( m_btShowCorners, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5 );


	m_panel101->SetSizer( sbSizer7 );
	m_panel101->Layout();
	sbSizer7->Fit( m_panel101 );
	bSizer4->Add( m_panel101, 1, wxEXPAND | wxALL, 5 );

	
	m_panel2->SetSizer( bSizer4 );
	m_panel2->Layout();
	bSizer4->Fit( m_panel2 );
	bSizer1->Add( m_panel2, 0, wxEXPAND, 5 );
	
	
	this->SetSizer( bSizer1 );
	this->Layout();
	m_statusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
	
	this->Centre( wxBOTH );
	
	// Connect Events
	m_btCamOpen1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::OpenCam1 ), NULL, this );
	m_btCapture1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CaptureCam1 ), NULL, this );
	m_btCamOpen2->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::OpenCam2 ), NULL, this );
	m_btCapture2->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CaptureCam2 ), NULL, this );
	m_btCamOpen3->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::OpenCam3 ), NULL, this );
	m_btCapture3->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CaptureCam3 ), NULL, this );
	m_btCaptureP1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CapturePair1 ), NULL, this );
	m_btCaptureP2->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CapturePair2 ), NULL, this );
	m_btShowCorners->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::ShowCorners ), NULL, this );

	m_camera=NULL;
}

MyFrame::~MyFrame()
{
	// Disconnect Events
	m_btCamOpen1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::OpenCam1 ), NULL, this );
	m_btCapture1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CaptureCam1 ), NULL, this );
	m_btCamOpen2->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::OpenCam2 ), NULL, this );
	m_btCapture2->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CaptureCam2 ), NULL, this );
	m_btCamOpen3->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::OpenCam3 ), NULL, this );
	m_btCapture3->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CaptureCam3 ), NULL, this );
	m_btCaptureP1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CapturePair1 ), NULL, this );
	m_btCaptureP2->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::CapturePair2 ), NULL, this );
	m_btShowCorners->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame::ShowCorners ), NULL, this );
	
	m_camera=NULL;
}

MyImagePanel* MyFrame::GetImagePanel1()
{
	return m_panDisplay1;
}

MyImagePanel* MyFrame::GetImagePanel2()
{
	return m_panDisplay2;
}

MyImagePanel* MyFrame::GetImagePanel3()
{
	return m_panDisplay3;
}

void MyFrame::OpenCam1(wxCommandEvent& event)
{
	if(m_camera->m_Cam1_isOpen)
	{
		m_camera->CloseCam1();
		m_stxtCamStatus1->SetLabel(wxT("Closed"));
		m_btCamOpen1->SetLabel(wxT("Open Camera"));

		m_statusBar->SetLabel(wxT("Camera 1 is Closed!"));
	}
	else
	{
		m_camera->OpenCam1();
		m_stxtCamStatus1->SetLabel(wxT("Open"));
		m_btCamOpen1->SetLabel(wxT("Close Camera"));

		m_statusBar->SetLabel(wxT("Camera 1 is Open!"));
	}
}

void MyFrame::OpenCam2(wxCommandEvent& event)
{
	if(m_camera->m_Cam2_isOpen)
	{
		m_camera->CloseCam2();
		m_stxtCamStatus2->SetLabel(wxT("Closed"));
		m_btCamOpen2->SetLabel(wxT("Open Camera"));

		m_statusBar->SetLabel(wxT("Camera 2 is Closed!"));
	}
	else
	{
		m_camera->OpenCam2();
		m_stxtCamStatus2->SetLabel(wxT("Open"));
		m_btCamOpen2->SetLabel(wxT("Close Camera"));

		m_statusBar->SetLabel(wxT("Camera 2 is Open!"));
	}
}

void MyFrame::OpenCam3(wxCommandEvent& event)
{
	if(m_camera->m_Cam3_isOpen)
	{
		m_camera->CloseCam3();
		m_stxtCamStatus3->SetLabel(wxT("Closed"));
		m_btCamOpen3->SetLabel(wxT("Open Camera"));

		m_statusBar->SetLabel(wxT("Camera 3 is Closed!"));
	}
	else
	{
		m_camera->OpenCam2();
		m_stxtCamStatus2->SetLabel(wxT("Open"));
		m_btCamOpen2->SetLabel(wxT("Close Camera"));

		m_statusBar->SetLabel(wxT("Camera 3 is Open!"));
	}
}

wxString MyFrame::GenStatus(String identity, int num)
{
	String status;
	String sNum = static_cast<ostringstream*>( &(ostringstream() << num) )->str();

	status="Image Captured Successfully from "+identity+":"+" Num "+sNum+".";

	wxString result(status.c_str(), wxConvUTF8);

	return result;
}

void MyFrame::CaptureCam1(wxCommandEvent& event)
{
	if(m_camera->m_Cam1_isOpen)
	{
		if(m_camera->CaptureCam1())
		{
			m_statusBar->SetLabel(GenStatus("Cam1",m_camera->m_numImageCam1));
		}
	}
	else
		wxMessageBox(wxT("Please Open Camera 1 First!"));
}

void MyFrame::CaptureCam2(wxCommandEvent& event)
{
	if(m_camera->m_Cam2_isOpen)
	{
		if(m_camera->CaptureCam2())
			m_statusBar->SetLabel(GenStatus("Cam2",m_camera->m_numImageCam2));
	}
	else
		wxMessageBox(wxT("Please Open Camera 2 First!"));
}

void MyFrame::CaptureCam3(wxCommandEvent& event)
{
	if(m_camera->m_Cam3_isOpen)
	{
		if(m_camera->CaptureCam3())
			m_statusBar->SetLabel(GenStatus("Cam3",m_camera->m_numImageCam3));
	}
	else
		wxMessageBox(wxT("Please Open Camera 3 First!"));
}

void MyFrame::CapturePair1(wxCommandEvent& event)
{
	if(m_camera->m_Cam1_isOpen && m_camera->m_Cam2_isOpen)
	{
		if(m_camera->CapturePair1())
			m_statusBar->SetLabel(GenStatus("Pair1",m_camera->m_numImagePair1));
	}
	else
		wxMessageBox(wxT("Please Make Sure both Camera 1 and 2 are Open!"));
}

void MyFrame::CapturePair2(wxCommandEvent& event)
{
	if(m_camera->m_Cam1_isOpen && m_camera->m_Cam2_isOpen)
	{
		if(m_camera->CapturePair2())
			m_statusBar->SetLabel(GenStatus("Pair2",m_camera->m_numImagePair2));
	}
	else
		wxMessageBox(wxT("Please Make Sure both Camera 2 and 3 are Open!"));
}

void MyFrame::ShowCorners(wxCommandEvent & event)
{
	if(m_camera->m_showCorners)
	{
		m_camera->m_showCorners=false;
		m_btShowCorners->SetLabel(wxT("Show Corners"));
	}
	else
	{
		m_camera->m_showCorners=true;
		m_btShowCorners->SetLabel(wxT("Hide Corners"));
	}
}
